package com.nc.delivery_project.server.domain;

import java.util.List;

/**
 * Created by miroshnik on 01.12.14.
 */
public class LegalPerson extends User {

    private String title;

    private List<ContactName> contactNames;
    private int legalPersonId;

    public LegalPerson() {
    }

    public LegalPerson(int userId, int legalPersonId, String title) {
        super(userId);
        this.title = title;
    }

    public LegalPerson(int legalPersonId) {
        this.legalPersonId = legalPersonId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public List<ContactName> getContactNames() {
        return contactNames;
    }

    public void setContactNames(List<ContactName> contactNames) {
        this.contactNames = contactNames;
    }
    
    public void setUser(User user) {
        setId(user.getId());
        setEmail(user.getEmail());
        setPassword(user.getPassword());
        setRole(user.getRole());
    }

    public int getLegalPersonId() {
        return legalPersonId;
    }

    public void setLegalPersonId(int legalPersonId) {
        this.legalPersonId = legalPersonId;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof LegalPerson)) return false;
        if (!super.equals(o)) return false;

        LegalPerson that = (LegalPerson) o;

        if (contactNames != null ? !contactNames.equals(that.contactNames) : that.contactNames != null) return false;
        if (title != null ? !title.equals(that.title) : that.title != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + (title != null ? title.hashCode() : 0);
        result = 31 * result + (contactNames != null ? contactNames.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("LegalPerson{");
        sb.append("title='").append(title).append('\'');
        sb.append(", contactNames=").append(contactNames);
        sb.append(", legalPersonId=").append(legalPersonId);
        sb.append(", email=").append(getEmail());
        sb.append('}');
        return sb.toString();
    }
}
